package per.sunmes.lesrb.pack;

import com.badlogic.gdx.audio.Sound;

import per.sunmes.lesrb.manager.SM;

public class SingletonSound {

	Sound sound;
	long soundPlayedId;
	boolean isLooping;
	boolean isPlaying;
	float volume = 1;

	float soundLiftTime;

	public SingletonSound(String path, boolean isAsseted) {
		if (isAsseted) {
			initSoundTarget(SM.getLoadAssetSound(path));
		} else {
			initSoundTarget(SM.getLoadOwnSound(path));
		}
	}

	public SingletonSound(Sound sound) {
		initSoundTarget(sound);
	}

	public void initSoundTarget(Sound sound) {
		this.sound = sound;
	}

	public void play() {
		play(false);
	}

	public void play(boolean loop) {
		if (isPlaying) {
			if (isLooping) {
				return;
			} else {
				stop();
			}
		}
		soundPlayedId = SM.cacheAndPlay(sound, loop, volume);
		isPlaying = true;
		isLooping = loop;
	}

	public void stop() {
		sound.stop(soundPlayedId);
		isPlaying = false;
	}

	////////

	public float getVolum() {
		return volume;
	}

	public void setVolum(float volume) {
		this.volume = volume;
		sound.setVolume(soundPlayedId, volume);
	}

	public Sound getSound() {
		return sound;
	}

	public float getSoundLiftTime() {
		return soundLiftTime;
	}

	public void setSoundLiftTime(float soundLiftTime) {
		this.soundLiftTime = soundLiftTime;
	}

	public long getSoundPlayedId() {
		return soundPlayedId;
	}

	public void setSoundPlayedId(long soundPlayedId) {
		this.soundPlayedId = soundPlayedId;
	}

	public boolean isLooping() {
		return isLooping;
	}

	public void setLooping(boolean isLooping) {
		this.isLooping = isLooping;
		sound.setLooping(soundPlayedId, isLooping);
	}

	public boolean isPlaying() {
		return isPlaying;
	}

}
